<template>
	<view class="visite">
	<model-page>
	<Search :searchResult="serchText">
		<view  @click="cancelSearch">
			取消
		</view>
	</Search>
	<Tabs :tabsList="tabsList" @change="changeTabs" ref="tabsRef"></Tabs>
	<view class="tables">
		<Table 
		:headList="headList" 
		:tableData="tableData" 
		:total="total" 
		v-model:pageNum="postData.pageNum"
		:pageSize="postData.pageSize"
		 @checkPage="checkPage"
		:stateList="stateList"
		></Table>
	</view>
	</model-page>
	</view>
</template>

<script setup>
import {ref,nextTick} from 'vue'
import Search from '@/component/Search.vue'
import Tabs from '@/component/Tabs.vue';
import Table from '@/component/Table.vue'
import {getlistByUser} from '@/api/leaveDate.js'
import {onLoad} from '@dcloudio/uni-app'
const tabsList = ref([
	{id:null,label:"全部"},
	{id:1,label:"审核中"},
	{id:2,label:"驳回"},
	{id:3,label:"已批准"},
	// {id:4,label:"已出院"},
	// {id:5,label:"已返院"},
	])
const headList = ref([
	{
	title:"房间",
	props:"buildRoomNum",
	width:"18%"	
	},
	{
	title:"老人名",
	props:"elderName",
	width:"18%"	
	},
	{
	title:"申请时间",
	props:"createTime",
	width:"34%"	
	},
	{
	title:"状态",
	props:"reviewStatus",
	width:"20%"	
	}
])
const stateList = [{
	id:1,
	label:"审核中",
	color:"#2778FF",
	path:"/packageLeaveDate/pages/leaveDateInfo/leaveDateInfo"
},{
	id:2,
	label:"驳回",
	color:"#D10707",
	path:"/packageLeaveDate/pages/leaveDateInfo/leaveDateInfo"
},
{
	id:3,
	label:"已批准",
	color:"#06C260",
	path:"/packageLeaveDate/pages/leaveDateInfo/leaveDateInfo"
},
{
	id:4,
	label:"已出院",
	color:"#ff9001",
	path:"/packageLeaveDate/pages/leaveDateInfo/leaveDateInfo"
},
{
	id:5,
	label:"已返院",
	color:"#ff9001",
	path:"/packageLeaveDate/pages/leaveDateInfo/leaveDateInfo"
}
]
const serchText = ref("")
const cancelSearch = ()=>{
	serchText.value = ""
	delete postData.value.elderId
     getleaveList()
}
// 切换
const changeTabs = (e)=>{
postData.value.pageNum = 1
if(e !== null){	
postData.value.reviewStatus = e
}else{
delete postData.value.reviewStatus
}
getleaveList()
}
// 切换分页
const checkPage = (type)=>{
	getleaveList()
}
//获取探望列表
const tableData = ref([])
const postData =ref({
	pageNum:1,
	pageSize:10,
	userId:uni.getStorageSync("userInfo").userId
}) 
const total = ref(0)
const getleaveList = async()=>{
	try{
		const {code,data:res} = await getlistByUser(postData.value)
		if(code === 200){
			total.value = res.total
			tableData.value = res.list
		}
	}catch(e){
		//TODO handle the exception
		return Promise.reject(e)
	}
}
const tabsRef = ref()
onLoad(()=>{
	uni.$on("undateElderId",(option)=>{
		const {type,searchResult} = option
		serchText.value = searchResult || ""
		delete postData.value.reviewStatus
		postData.value.pageNum = 1
		postData.value.elderId = type
		nextTick(()=>{
			tabsRef.value.changeTabs(0,null)
		})
	})
	getleaveList()
})
</script>

<style lang="less" scoped>
	.visite{
		.tables{
			margin-top: 45rpx;
		}
	}
</style>